import { Injectable } from '@angular/core';

// 服务
import { HttpService } from '../../../http/http.service';

import { EventListen,EventListenList,EventListenResult } from './eventlisten';

@Injectable()
export class EventListenService {

    constructor(
        private httpService: HttpService
    ) { }

    // 查询监听配置
    find(count: number, etype: string, action: string, previd: string): Promise<EventListenList> {
        var param = new Map();
        if (count < 5) {
            count = 5;
        }
        param.set("count", count);
        if (etype != "") {
            param.set("etype", etype)
        }
        if (action != "") {
            param.set("action", action)
        }
        if (previd != "") {
            param.set("previd", previd)
        }
        return this.httpService.getJSON<EventListenList>('/admin/listen', param);
    }
// 新增监听配置
    add( el :EventListen): Promise<EventListenResult> {
        
        return this.httpService.postJSON<EventListenResult>('/admin/listen', el);
    }
    del( rid:string): Promise<EventListenResult> {
        return this.httpService.deleteJSON<EventListenResult>('/admin/listen/'+rid);
    }
    // 修改监听配置
    update( el :EventListen): Promise<EventListenResult> {
        var param = new Map();
        param.set("etype",el.etype);
        param.set("action",el.action);
        param.set("hookurl",el.hookurl);
        param.set("from",el.from);
        return this.httpService.putJSON<EventListenResult>('/admin/listen/'+el.rid, el);
    }
}